clc;
clear;

f1 = @(x) sqrt(4 - sin(x).^2);
f2 = @(x) sin(x)./x;

a = 0;b = 2; n1 = 10;n2 = 20;

fprintf('\nCompound trapezoidal formula\n');
I1 = CompTrapFormula(f1,n1,a,b);
I2 = CompTrapFormula(f1,n2,a,b);
I3 = CompTrapFormula(f2,n1,a,b);
I4 = CompTrapFormula(f2,n2,a,b);
fprintf('I1 = %f\nI2 = %f\nI3 = %f\nI4 = %f\n',I1,I2,I3,I4);

fprintf('\nCompound Simpson quadrature formula\n');
I1 = CompSimpQuadFormula(f1,n1,a,b);
I2 = CompSimpQuadFormula(f1,n2,a,b);
I3 = CompSimpQuadFormula(f2,n1,a,b);
I4 = CompSimpQuadFormula(f2,n2,a,b);
fprintf('I1 = %f\nI2 = %f\nI3 = %f\nI4 = %f\n',I1,I2,I3,I4);

fprintf('\nCompound Gauss Legendre quadrature formula\n');
I1 = CompGLQuadFormula(f1,n1,a,b);
I2 = CompGLQuadFormula(f1,n2,a,b);
I3 = CompGLQuadFormula(f2,n1,a,b);
I4 = CompGLQuadFormula(f2,n2,a,b); 
fprintf('I1 = %f\nI2 = %f\nI3 = %f\nI4 = %f\n',I1,I2,I3,I4);
